"""
演示python pymysql库的基础操作
"""

from pymysql import Connection
# 构建到mysql数据库的链接
conn=Connection(
    host="localhost",       # 主机名
    port=3306,      # 端口号
    user="root",     #账户
    password="123456"   # 密码
)
# print(conn.get_server_info())

# 执行非查询性质sql
cusor=conn.cursor()     # 获取到游标对象
# 选择数据库
conn.select_db("db1")

# 执行sql
# cusor.execute("create table test_pymysql(id int)")
cusor.execute("select * from stu")

results=cusor.fetchall()
for r in results:
    print(r)

conn.close()